<?php

namespace app\api\controller\stall;

use app\api\controller\Controller;
use app\api\model\order\Order as OrderModel;
use app\api\model\stall\Apply as ApplyModel;
use app\Request;
use app\supplier\model\stall\Category as CategoryModel;

class Category extends Controller
{
    public function productcate(Request $request)
    {
        $id = $request->param('stall_id') ?? 0;
        $detail = ApplyModel::getdetail($id);
        if (!$detail) {
            return $this->renderError('店铺不存在');
        }
        $user = $this->getUser();
        //首单数据
        $OrderModel = new OrderModel;
        $firstOrder = $OrderModel->getCount($user, 'all', true);
        $firstYN = ($firstOrder > 0) ? 1 : 0; //会员：2全部，1普通会员，0新人
        $model = new CategoryModel;
        $list = $model->getStallCateTree($id, $detail['shop_supplier_id']);
        foreach ($list as $key => &$item) {
            if ($firstYN == 1 && $item['type'] == 1) {
                unset($list[$key]);
                $list = array_values($list);
            }
        }
        return $this->renderSuccess('', compact('list'));
    }
}